package view.panel.mail
{
	import control.panel.IPanelControl;
	import control.table.MailControl;
	
	import flash.events.MouseEvent;
	
	import model.room.MailData;
	
	import utils.TextTool;
	
	import view.components.ImgButton;
	import view.components.list.ITileListItem;
	import view.components.list.TileList;
	import view.panel.AbsPanel;

	public class MailPanel extends AbsPanel
	{
		private var mailList:TileList;
		
		public function MailPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			defaultX = 6;
			defaultY = 105;
			resetBg(215,282);
			initCloseBut();
			resetCloseBut();
			dropShadow();
			initTweenPanelOpen();
			
			initList();
			initText();
			initButs();
			
		}
		
		private function initButs():void
		{
			addChild(new ImgButton(43,250,0,onBut,45,24,"butBg",null,"接受"));
			addChild(new ImgButton(113,250,0,onBut,45,24,"butBg",null,"拒绝"));
		}
		
		private function onBut(event:MouseEvent):void
		{
			close();
		}
		
		private function initText():void
		{
			addChild(TextTool.getTextFieldXY(20,5,150,20,12,0xFFFFFF,"以下玩家邀请你加为牌友:"));
		}
		
		private function initList():void
		{
			var listItem:ITileListItem = new MailItem();
			mailList = new TileList(170,210,listItem,true);
			mailList.x = 21;
			mailList.y = 32;
			addChild(mailList);
		}
		
		public function update(datas:Array):void
		{
			for each (var data:MailData in datas)
			{
				mailList.addItem(data,true);
			}
		}
		
		override public function close() : void
		{
			super.close();
			(panelControl as MailControl).mailResult();
		}
		
		public function clear():void
		{
			mailList.removeAll();
		}
		
	}
}